package cn.example.fragmenttest3;


import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener ,Fragment_line.CallBackValue{

    private Button button_fragment;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        button_fragment=findViewById(R.id.button);
        button_fragment.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            //发送数据
            case R.id.button:
                android.support.v4.app.FragmentManager manager = getSupportFragmentManager();
                android.support.v4.app.FragmentTransaction transaction = manager.beginTransaction();
                Fragment_line fragment = new Fragment_line();
                Bundle bundle = new Bundle();
                bundle.putString("frag1","activity数据来了");
                fragment.setArguments(bundle);
                transaction.add(R.id.my_fragment, fragment);
                transaction.commit();
                Toast.makeText(MainActivity.this,"以已经发送到fragment",Toast.LENGTH_SHORT).show();
                break;
        }
    }

/*
 //要获取的值  就是这个参数的值  获取fragment 传来的值
 */
    @Override
    public void SendMessageValue(String strValue) {
       Toast.makeText(MainActivity.this,"获取的内容"+strValue,Toast.LENGTH_SHORT).show();
    }
}
